package com.lmaos.basetools.base.calculate;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import com.lmaos.basetools.base.SNumberUtils;

public class SCalculateModeJavaScript implements SCalculateMode{
	ScriptEngineManager manager = new ScriptEngineManager();
	ScriptEngine engine = manager.getEngineByName("JavaScript");
	@Override
	public double calculate(String format) {
		Object obj = null;
		try {
			obj = engine.eval(format);
		} catch (ScriptException e) {
			e.printStackTrace();
		}
		return SNumberUtils.toDouble(obj);
	}
}
